package com.jz.banner.screen.permission

import android.content.Context
import android.text.TextUtils
import com.jz.banner.screen.R
import com.yanzhenjie.permission.Permission
import com.yanzhenjie.permission.Rationale
import com.yanzhenjie.permission.RequestExecutor

/**
 * 创建者     Noel
 * 创建时间   2018/1/31 15:14
 * 描述	      权限 提示框。
 */
class DefaultRationale : Rationale {

    override fun showRationale(context: Context, permissions: List<String>, executor: RequestExecutor) {
        val permissionNames = Permission.transformText(context, permissions)
        val message = context.getString(R.string.message_permission_rationale, TextUtils.join("\n", permissionNames))

        AlertDialog.newBuilder(context)
            .setCancelable(false)
            .setTitle(R.string.cancel)
            .setMessage(message)
            .setPositiveButton(R.string.resume) { dialog, which -> executor.execute() }
            .setNegativeButton(R.string.cancel) { dialog, which -> executor.cancel() }
            .show()
    }
}